package com.zhima.controller.feign;

import com.zhima.dto.FeignQuestionBasicInfoDTO;
import com.zhima.dto.FeignQuestionJudgeInfoDTO;
import com.zhima.dto.FeignQuestionJudgeScoreInfoDTO;
import com.zhima.service.OjQuestionPublishService;
import com.zhima.vo.QuestionBankContestEditQuestionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : Administer
 * @date : 2023-09-05 15:20
 **/
@RestController
@RequestMapping("/question/feign")
public class QuestionFeignController {

    @Autowired
    private OjQuestionPublishService ojQuestionPublishService;

    /**
     * 根据{questionId}获取题目的版本号
     *
     * @param questionId
     * @return
     */
    @GetMapping("/version/{questionId}")
    public Long queryQuestionVersion(@PathVariable("questionId") Long questionId) {
        return ojQuestionPublishService.queryQuestionVersion(questionId);
    }

    /**
     * 根据{questionId}获取题目的基本信息
     *
     * @param questionId
     * @return
     */
    @GetMapping("/q/{questionId}")
    public FeignQuestionBasicInfoDTO queryQuestionBasicInfo(@PathVariable("questionId") Long questionId) {
        return ojQuestionPublishService.queryQuestionBasicInfo(questionId);
    }

    /**
     * 根据{questionId}获取题目的关于测评的信息
     *
     * @param questionId
     * @return
     */
    @GetMapping("/t/{questionId}")
    public FeignQuestionJudgeInfoDTO queryQuestionJudgeInfo(@PathVariable("questionId") Long questionId) {
        return ojQuestionPublishService.queryQuestionJudgeInfo(questionId);
    }

    /**
     * 根据{questionId}获取题目的关于测评分数需要的信息
     *
     * @param questionId
     * @return
     */
    @GetMapping("/s/{questionId}")
    public FeignQuestionJudgeScoreInfoDTO queryQuestionJudgeScoreInfo(@PathVariable("questionId") Long questionId) {
        return ojQuestionPublishService.queryQuestionJudgeScoreInfo(questionId);
    }

    /**
     * 增加指定题目的总提交次数
     *
     * @param questionId
     * @return
     */
    @PostMapping("/submit/{questionId}")
    public boolean increaseSubmitNum(@PathVariable("questionId") Long questionId) {
        return ojQuestionPublishService.increaseSubmitNum(questionId);
    }

    /**
     * 增加{questionId}的总AC次
     *
     * @param questionId
     * @return
     */
    @PostMapping("/ac/{questionId}")
    public boolean increaseAcNum(@PathVariable("questionId") Long questionId) {
        return ojQuestionPublishService.increaseAcNum(questionId);
    }

    @PutMapping("/assemble")
    public List<QuestionBankContestEditQuestionVO> assembleQuestion(@RequestBody List<Long> questionIds) {
        return ojQuestionPublishService.assembleQuestion(questionIds);
    }

    @GetMapping("/id-to-number/{questionNumber}")
    public Long getQuestionIdByQuestionNumber(@PathVariable("questionNumber") String questionNumber) {
        return ojQuestionPublishService.getQuestionIdByQuestionNumber(questionNumber);
    }

    @PostMapping("/fullMarks")
    public List<Integer> listFullMarks(@RequestBody List<Long> questionIds) {
        return ojQuestionPublishService.listFullMarks(questionIds);
    }
}
